<template>
    <div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.keyword" placeholder="商品名称 / 查询" class="handle-input mr10" clearable></el-input>
                <el-button type="primary" icon="el-icon-search" @click="func_handleSearch" plain>搜索</el-button>
            </div>
            <el-table :data="productTableData" border class="table" header-cell-class-name="table-header">
				<el-table-column prop="id" label="ID" width="55" align="center" v-if="false"></el-table-column>
				<el-table-column label="序号" width="80" align="center"><template #default="scope">
						{{scope.$index + 1}}
				</template></el-table-column>
				<!-- <el-table-column label="展示图片" align="center" width="150px">
                    <template #default="scope">
                        <el-image style="padding: 5px 5px 5px 5px" 
						:src="scope.row.urlPic" fit="cover" 
						:preview-src-list="scope.row.contentPicList"
						@click.native="func_showBigPic(scope.$index, scope.row)"
						/>
                    </template>
				</el-table-column> -->
                <el-table-column prop="productBoardName" label="品牌名称" width="150px" align="left"></el-table-column>
				<el-table-column prop="productName" label="商品名称" align="left"></el-table-column>
				<el-table-column prop="price" label="售价" width="100px" align="right"></el-table-column>
				<el-table-column prop="uprice" label="会员价格" width="100px" align="right"></el-table-column>
				<el-table-column prop="shipmentPrice" label="运费" width="100px" align="right">
                    <template #default="scope">
                        {{scope.row.shipmentPrice === null ? 0 : scope.row.shipmentPrice }}
                    </template>
				</el-table-column>
				<el-table-column prop="strIsPublish" label="发布状态" width="150px" align="right"></el-table-column>
				<!-- <el-table-column prop="productDescribe" label="描述" align="left"></el-table-column> -->
				<el-table-column prop="shipmentProvince" label="发货省份" width="150px" align="center"></el-table-column>
                <el-table-column label="操作" :width="optColumnWidth" align="center" >
                    <template #default="scope">
						<el-button type="text" icon="el-icon-delete" class="red mr10" @click="func_handleDelete(scope.$index, scope.row)">删除</el-button>
                        <el-dropdown :hide-on-click="false">
                            <span class="el-dropdown-link green mr10"><el-icon class="el-icon-lx-info mr10" />更多</span>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-button type="text" icon="el-icon-lx-refresh" class="success ml10 mr10" @click="func_handleRecover(scope.$index, scope.row)">恢复</el-button>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex"
                    :page-size="query.pageSize" :total="pageTotal" @current-change="func_handlePageChange"></el-pagination>
            </div>
        </div>
        <!-- ---------------------------------------------------------------------------------------------------------------------- -->
    </div>
</template>
<script>
import { ref, reactive, toRefs } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus';
import { findDropProductInfoListPage, recoveryProduct, deleteProductById} from '../../../api/hairmanager/products';

import { NO_DATA_SELECT_ERROR, SUCCESS_ADDDATA_DIALOG_MESSAGE, SUCCESS_DELDATA_DIALOG_MESSAGE, SUCCESS_EDITDATA_DIALOG_MESSAGE, formLabelWidth, } from "../../../api/CommonErrorMessage.js";

export default {
    name: "serviceProject",
    components: {},
    setup() {
        const router = useRouter();
        //主数据条件查询
        const query = reactive({
            keyword: '',
            isPublish: '',
            pageIndex: 1,
            pageSize: 10,
        });
        // 主数据总页数
        const pageTotal = ref(0);
        // 主数据表格
        let productTableData = ref([]);
        const optColumnWidth = 150;
        // =========================================================================================================

        // 主业务处理 ========================================================================================= END
        /**
         * @name 获取表格数据
         */
        const func_getData = () => {
            findDropProductInfoListPage(query).then((res) => {
                productTableData.value = res.data.list;
                pageTotal.value = res.data.total;
            });
        };
        func_getData();
        /**
         * @name 主数据查询操作
         */
        const func_handleSearch = () => {
            query.pageIndex = 1;
            func_getData();
        };
        /**
         * @name 分页导航
         */
        const func_handlePageChange = (val) => {
            // query.pageIndex = val;
            query['pageIndex'] = val;
            func_getData();
        };
        /**
         * @name 删除商品数据操作
         */
        const func_handleDelete = (index, row) => {
            // 二次确认删除
            ElMessageBox.confirm("确定要删除吗？", "提示", {
            type: "warning",
            }).then(() => {
                func_delDialogEdit(row['id']);
            }).catch(() => {});
        };
		const func_handleRecover = (index, row) => {
            let obj = {id: row['id']};
            recoveryProduct(obj).then((res)=>{
                if(res.code != 200) {
                    if(res.type == 0) {
                        ElMessage.warning(res.data.msg);
                    } else {
                        ElMessage.error(res.data.msg);
                    }
                } else {
                    ElMessage.success(SUCCESS_DELDATA_DIALOG_MESSAGE);
                    func_getData(); // 刷新数据
                }
            });
		};
        /**
         * @name 删除商品配置
         */
        const func_delDialogEdit = (id) => {
            deleteProductById(id).then((res)=>{
                if(res.code != 200) {
                    if(res.type == 0) {
                        ElMessage.warning(res.data.msg);
                    } else {
                        ElMessage.error(res.data.msg);
                    }
                } else {
                    ElMessage.success(SUCCESS_DELDATA_DIALOG_MESSAGE);
                    func_getData(); // 刷新数据
                }
            });
        };
        // 主业务处理 ========================================================================================= END
        // =========================================================================================================
        return {
            // 系统环境变量
            optColumnWidth, query, pageTotal,
            func_handleSearch, func_handlePageChange,
            // 主业务处理
            func_getData, productTableData, func_handleDelete, func_handleRecover, func_delDialogEdit,
        };
    },
};
</script>
<style scoped>
.handle-box {
    margin-bottom: 20px;
}
.handle-select {
    width: 120px;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.green {
    color: #67c23a;
}
.mr10 {
    margin-right: 10px;
}
.ml10 {
    margin-left: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>